package bb.lanxing.devices.sync;

import com.garmin.fit.RecordMesg;
import com.garmin.fit.ZonesTargetMesg;
import bb.lanxing.calc.data.SourcePoint;
import bb.lanxing.device.sync.FitHelper;
import bb.lanxing.lib.devices.sync.FitTrans;
import bb.lanxing.model.database.Workout;

public class SprintFitProcessor extends DefaultFitProcessor {
    private Workout workout;

    public SprintFitProcessor() {
        super(3);
    }

    @Override
    public void onStart(FitTrans fitTrans) {
        super.onStart(fitTrans);
        this.workout = getWorkout();
    }

    @Override
    public void onRecordMesg(RecordMesg recordMesg) {
        Workout workout = this.workout;
        if (workout != null && workout.getSport() == Workout.TYPE_TRAINING) {
            SourcePoint createSourcePointByFitMesg = FitHelper.createSourcePointByFitMesg(recordMesg, getSourceType());
            if (createSourcePointByFitMesg == null) {
                return;
            }
            processSourcePoint(createSourcePointByFitMesg);
            return;
        }
        super.onRecordMesg(recordMesg);
    }

    @Override
    protected void onZonesTargetMesg(ZonesTargetMesg zonesTargetMesg) {
        Integer functionalThresholdPower = zonesTargetMesg.getFunctionalThresholdPower();
        Workout workout = getWorkout();
        if (functionalThresholdPower == null || workout == null) {
            return;
        }
        workout.setPowerFTP(functionalThresholdPower);
    }
}
